package com.yiligi.myserver.mapper;

import com.yiligi.myserver.pojo.DTO.ChangeUserPasswordDTO;
import com.yiligi.myserver.pojo.DTO.UserDTO;
import com.yiligi.myserver.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT * from sys_user")
    List<User> selectAllUser();

    @Insert("INSERT into sys_user(username,nickname,email,phone,address)"+
    "VALUES (#{username},#{nickname},#{email},#{phone},#{address})")
    int insertUser(User user);

    @Select("select * from sys_user where id = #{id} ")
    User selectUserById(@Param("id") int id);

    int updateUser(User user);

    @Delete("DELETE from sys_user where id = #{id}")
    Integer deleteUserById(@Param("id")Integer id);

    //@Select("select * from sys_user where username like concat('%', #{username}, '%') or email like concat('%', #{email}, '%') or address like concat('%', #{address}, '%') limit #{pageNum}, #{pageSize}")
    List<User> selectPage(
            @Param("pageNum")int pageNum,
            @Param("pageSize")int pageSize,
            @Param("username")String username,
            @Param("email")String email,
            @Param("address")String address
    );
   // @Select("select count(*) from sys_user where username like concat('%', #{username}, '%')"+
   //         " or email like concat('%', #{email}, '%') or address like concat('%', #{address}, '%')")
    Integer selectTotal(@Param("username")String username, @Param("email")String email, @Param("address")String address);

    Boolean addBatchUser(List<User> users);

    @Select("select username,password,nickname,avatar_url from sys_user where username = #{username}")
    UserDTO login(UserDTO userDTO);

    @Select("select username from sys_user where username = #{username}")
    String valUserName(@Param("username")String username);

    @Insert("insert into sys_user(username,password,nickname) values(#{username},#{password},#{nickname})")
    int registerUser(User user);

    @Select("select * from sys_user where username = #{username} ")
    User selectUserByName(@Param("username")String username);

    @Update("update sys_user set password = #{newPassword} where username = #{username};")
    Boolean changeUserPassword(ChangeUserPasswordDTO user);

    @Select("select password from sys_user where username = #{username};")
    String selectUserPassword(@Param("username")String username);
}
